<?php
class userControl extends Control {

    //显示用户列表
    function index() {
        $db = m('user');
        $total = $db->count();
        $page=new page($total,"10",3,1);
        $users = $db->order("userid desc")->all($page->limit());
        $page=$page->show();
        $this->assign('total', $total);
        $this->assign("users", $users);
        $this->assign("page", $page);
        $this->display();
    }
    //添加用户
    function addUser() {
        // p($_SERVER);die;
        if (!empty($_POST)) {
            $_POST['password'] =$_POST['password'];
            $_POST['registime'] = $_SERVER['REQUEST_TIME'];
            $_POST['logintime'] = $_SERVER['REQUEST_TIME'];
            $_POST['regisip'] = $_SERVER['REMOTE_ADDR'];
            $_POST['loginip'] = $_SERVER['REMOTE_ADDR'];
            // p($_POST);die;
            $db = m('user');
            if ($db->add()) {
                go("index");
            }   
        }
        $this->display();
    }

    //锁定用户
    function lockUser() {
        $db = M("user");
        $uid = $_GET['uid'];
        if ($db->save(array("userid" => $uid, "lock" => $_GET['lock']))) {
            go("index");
        } else {
            $this->error("修改失败", "index");
        }
    }

    //修改用户
    function editUser() {
        // p($_POST);die;
        if (!empty($_POST)) {
            $db = m('user');
            if ($db->update()) {
                go("index");
            } else {
                $this->error("修改失败", "index");
            }
        }
        $uid = (int) $_GET['uid'];
        $db = m('user');
        $user = $db->find('userid = ' . $uid);
        $this->assign("user", $user);
        $this->display();
    }

    //删除用户
    function delUser() {
        $db = m('user');
        $uid = (int) $_GET['uid'];
        if ($db->del('userid = ' . $uid)) {
            $this->success("删除用户成功", "index");
        } else {
            $this->error("删除用户失败", "index");
        }
    }

   
}

?>
